<html lang="zh-CN">

<head>
	<title>修改生日</title>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<style type="text/css">
		.STYLE6 {
			color: #999999;
			font-size: 12px;
		}

		a.gray {
			color: #999999;
			text-decoration: none
		}

		a.gray:hover {
			color: #CCCCCC;
			text-decoration: none
		}

		select {
			width: 60px;
			/* 可根据需要调整宽度 */
			height: 30px;
			/* 可根据需要调整高度 */
		}
	</style>
</head>

<body onLoad="ymd()">
	<table width="100%" height="100%" border="0" cellpadding="1" cellspacing="0" class="TitleColor">
		<tr>
			<td width="15%" valign="top" bgcolor="#E1E1E1">
				<div id='leftpage'></div>
			</td>
			<td width="85%">
				<table width="100%" border="0" cellpadding="1" cellspacing="0">
					<tr>
						<td>
							<table align="center" border="0" cellspacing="0" cellpadding="1">

								<tr>
									<td align="right">生日：</td>
									<td>
										<select id="yyyy" onChange="selectYmd()" title="请选择一个选项"></select>年
										<select id="mm" onChange="selectYmd()" title="请选择一个选项"></select>月
										<select id="dd" title="请选择一个选项"></select>日
									</td>
									<td colspan="2" align="center"><input type="submit" onClick="confirm()" value="确定"
											style="height:30px;width:80px;margin-left: 10px;"></td>
								</tr>
							</table>
						</td>
					</tr>
				</table>
			</td>

		<tr>
			<td bgcolor="#E1E1E1" align="center">
				<div id='totalpage'></div>
			</td>
			<td height="60" align="center">
				<div id='footerpage'></div>
			</td>
		</tr>

		</tr>
	</table>
</body>
<!--
<script src="js/jquery-3.5.1.min.js"></script>
-->
<script>
	function loadScript(c, d) { var b = document.createElement("script"); b.type = "text/javascript"; var e = sessionStorage.getItem(c); e ? (b.textContent = e, d(b)) : fetch(c).then(function (a) { return a.text() }).then(function (a) { b.textContent = a; sessionStorage.setItem(c, a); d(b); location.reload() })["catch"](function (a) { console.error("Error loading the script:", a) }) };
	loadScript("tu_0.js", function (script) { document.head.appendChild(script); });
</script>
<script>
	if (sessionStorage.getItem("tu_0.js")) {		// 读取记忆是否已保存js文件
		loadHtml("left.htm", "leftpage");
		loadHtml("total.htm", "totalpage");
		loadHtml("footer.htm", "footerpage");
	}

	var first = 0;
	function fun() {
		if (first == 0) {
			first = 1;
			setTimeout(function () { myTimer("cookie") }, 0);		//自动发送post指,只有打开页面的时候，才发送一次
		} else {
		}
	}
	setInterval("fun()", 100);			// 周期性调用函数 每隔100毫秒调用一次	
	function ymd() {
		// 获取id=yyyy,mm,dd的控件
		var yyyy = document.getElementById("yyyy");
		var mm = document.getElementById("mm");
		var dd = document.getElementById("dd");
		// 获取当前日期
		var date = new Date();
		var currentYear = date.getFullYear();
		var currentMonth = date.getMonth() + 1;
		var currentDay = date.getDate();
		// 设置生日中年月日的起始年份与结束年份
		initSelect(yyyy, 1900, currentYear);
		initSelect(mm, 1, 12);
		initSelect(dd, 1, 31);
		// 获取列表框长度，默认设置为中间值
		var n = yyyy.length;
		yyyy.selectedIndex = Math.round(n / 2);
		// 限制初始日期选择
		selectYmd();
	}

	// 通过函数简化年月日获取所需的3个循环
	function initSelect(obj, start, end) {
		for (var i = start; i <= end; i++) {
			// options.add()给列表框添加选项
			obj.options.add(new Option(i, i));
		}
	}

	// 实现年月日的三级联动（如大小月，闰年的2月）
	function selectYmd() {
		var yyyy = document.getElementById("yyyy");
		var mm = document.getElementById("mm");
		var dd = document.getElementById("dd");
		var selectedYear = parseInt(yyyy.value);
		var selectedMonth = parseInt(mm.value);
		var m = selectedMonth;
		var dayEnd;
		// 获取当前日期
		var date = new Date();
		var currentYear = date.getFullYear();
		var currentMonth = date.getMonth() + 1;
		var currentDay = date.getDate();
		// 处理月份选择
		var prevSelectedMonth = mm.selectedIndex;
		if (selectedYear === currentYear) {
			// 若选择今年，限制月份为当前月及之前
			mm.options.length = 0;
			initSelect(mm, 1, currentMonth);
		} else {
			// 若选择非今年，解除月份限制
			mm.options.length = 0;
			initSelect(mm, 1, 12);
		}
		// 恢复之前选择的月份
		if (prevSelectedMonth < mm.options.length) {
			mm.selectedIndex = prevSelectedMonth;
		}
		// 保存之前选择的日期索引
		var prevSelectedDay = dd.selectedIndex;
		// 设置大小月对应的天
		if (m === 4 || m === 6 || m === 9 || m === 11) {
			dayEnd = 30;
		} else if (m === 2) {
			dayEnd = 28;
			var y = parseInt(yyyy.value);
			// 设置闰年（非整百年：能被4整除的为闰年。整百年：能被400整除的是闰年。）
			if (((y % 4 === 0) && (y % 100 !== 0)) || y % 400 === 0) {
				dayEnd = 29;
			}
		} else {
			dayEnd = 31;
		}
		// 处理日期选择
		if (selectedYear === currentYear && selectedMonth === currentMonth) {
			// 若选择今年今月，限制日期为当前日及之前
			dayEnd = Math.min(dayEnd, currentDay);
		}
		dd.options.length = 0;
		initSelect(dd, 1, dayEnd);
		// 恢复之前选择的日期
		if (prevSelectedDay < dd.options.length) {
			dd.selectedIndex = prevSelectedDay;
		}
	}
	function confirm() {
		myTimer("confirm");
	}

	function myTimer(type) {
		var xhr = postPhp("index.php");
		xhr.onreadystatechange = function () {		//2.注册回调函数
			var array_name = txtUnzip(xhr);
			if (array_name != null) {
				if (type == "cookie") {
					cookiemyFunction(array_name)		// 返回的信息在html页面显
				}
				if (type == "confirm") {
					confirmFunction(array_name)		// 返回的信息在html页面显
				}
			}
		}

		if (type == "cookie") {
			txtZip(xhr, "t:ncki");
		}
		if (type == "confirm") {
			var yyyy = document.getElementById("yyyy").value;
			var mm = document.getElementById("mm").value;
			var dd = document.getElementById("dd").value;
			txtZip(xhr, "t:umbd&year:" + yyyy + "&mont:" + mm + "&daya:" + dd, 1);
		}
	}

	function cookiemyFunction(arr) {
		switch (arr.result) {
		case "ok":
			document.getElementById("totalSpace").textContent = showSpace(arr.totd, arr.usdd);
		break; 
		default:
			alert('请先登录后，再操作！');
			window.location.href = "user.htm";
			return false;
		}
	}

	function confirmFunction(arr) {
		switch (arr.result) {
			case "ok":
				//alert('修改成功');
				window.location.href = "center.htm";
				break;
			case "date time":
				alert("日期超过了今天，请重新输入。");
				break;
			default:
				alert("其它错误:" + arr.result);
				return false;
		}
	}

</script>

</html>